package demo.annotation;


import com.alibaba.fastjson.JSONObject;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
/**
 * @author lingyun.wang on @date 2021/11/3
 */
public class GetAnnotationValueUtil {
    public static String[] check(){
        List<Method>  list = Arrays.asList(TestAnnotation.class.getMethods());
        for(int i=0;i<list.size();i++){
            Method method = list.get(i);
            if(method.isAnnotationPresent(MyAnnotation.class)){//是否使用MyAnno注解
                MyAnnotation annott = method.getAnnotation(MyAnnotation.class);
                System.out.println(JSONObject.toJSONString(annott.value()));
                for (Annotation anno : method.getDeclaredAnnotations()) {//获得所有的注解
                    if(anno.annotationType().equals(MyAnnotation.class) ){//找到自己的注解
                        System.out.println(((MyAnnotation)anno).value());
                        return ((MyAnnotation)anno).value();
                    }
                }

            }

        }
        return null;
    }
}
